package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.GoodsDao;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.Goods;
import com.atguigu.jxc.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author 花鸟の虫鱼
 * @CreateDate 21/9/6 14:04
 * @Version 1.0
 * @Description TODO
 */
@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsDao goodsDao;

    @Override
    public Map<String, Object> selectlist(Integer page, Integer rows, String goodsName, Integer goodsTypeId) {
        Map<String, Object> map = new HashMap<>();
        //  当前页页码
        page = page == 0 ? 1 : page;
        //  当前页总记录数
        int offSet = (page - 1) * rows;
        List<Goods> goodsList = goodsDao.getList(offSet, rows, goodsName,goodsTypeId);
        map.put("total", goodsDao.getListCount(goodsTypeId));
        map.put("rows", goodsList);
        return map;
    }

    @Override
    public Map<String, Object> selectlistAlarm() {
        Map<String, Object> map = new HashMap<>();
        List<Goods> alarmList = goodsDao.getlistAlarm();
        map.put("rows",alarmList);
//        map.put("total",goodsDao.getAlarmCount());
        return map;
    }


    @Override
    public Map<String, Object> selectInventory(Integer page, Integer rows, String codeOrName, Integer goodsTypeId) {
        Map<String, Object> map = new HashMap<>();
        //  当前页页码
        page = page == 0 ? 1 : page;
        //  当前页总记录数
        int offSet = (page - 1) * rows;

        List<Goods> goodsList = goodsDao.getGoodsList(offSet, rows, codeOrName,goodsTypeId);
        map.put("total", goodsDao.getGoodsCount(goodsTypeId));
        map.put("rows", goodsList);
        return map;
    }

    @Override
    public Map<String, Object> selectNoInventoryQuantity(Integer page, Integer rows, String nameOrCode) {
        Map<String, Object> map = new HashMap<>();
        //  当前页页码
        page = page == 0 ? 1 : page;
        //  当前页总记录数
        int offSet = (page - 1) * rows;

        List<Goods> noInventoryQuantityList = goodsDao.getNoInventoryQuantityList(offSet, rows, nameOrCode);
        map.put("total", goodsDao.getNoInventoryQuantityCount(nameOrCode));
        map.put("rows", noInventoryQuantityList);
        return map;
    }

    @Override
    public Map<String, Object> selectHasInventoryQuantity(Integer page, Integer rows, String nameOrCode) {
        Map<String, Object> map = new HashMap<>();
        //  当前页页码
        page = page == 0 ? 1 : page;
        //  当前页总记录数
        int offSet = (page - 1) * rows;

        List<Goods> hasInventoryQuantityList = goodsDao.getHasInventoryQuantityList(offSet, rows, nameOrCode);
        map.put("total", goodsDao.getHasInventoryQuantityCount(nameOrCode));
        map.put("rows", hasInventoryQuantityList);
        return map;
    }

    @Override
    public ServiceVO saveStock(Goods goods) {
        //  id不为空执行更新方法
        goodsDao.updateGoods(goods);

        return new ServiceVO<>(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }

//    @Override
//    public ServiceVO deleteStock(Integer goodsId) {
//        String[] goodsIdList = goodsId.(",");
//        goodsDao.deleteSupplier(goodsIdList);
//        return new ServiceVO<>(SuccessCode.SUCCESS_CODE, SuccessCode.SUCCESS_MESS);
//    }
}
